package com.lz.football.module.guide.view
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.leagueMatch.view.PreMatchPanel;
	import com.lz.football.module.task.view.TaskView;
	
	import common.match.MatchPanel;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.managers.AnimationManager;

	/**
	 *任务 引导  比赛 
	 * @author lake
	 * 
	 */	
	public class TaskGuideView extends Guide
	{
		public function TaskGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			initDialog_1();
		}
		/**
		 * 场景内对话框 
		 *	任务
			官方：升级的最佳途径！
			1L：没有之一！
			2L：来个结婚的任务吧！
			3L：。。。。
		 * 
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_11");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			removeBgMark();
			//限制区域
			var rectPoint :Point = TaskView.firstTaskSkin.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,TaskView.firstTaskSkin.width,TaskView.firstTaskSkin.height);
			step();
			//指向任务条
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  TaskView.firstTaskSkin;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(MainEvent.OPEN_LEAGUEMATCH_VIEW,openViewH);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *打开界面 
		 * @param e
		 * 
		 */		
		private function openViewH(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(MainEvent.OPEN_LEAGUEMATCH_VIEW,openViewH);
			removeArrowMc();
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			removeBgMark();
			//限制区域
			var rectPoint :Point = PreMatchPanel.challengeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PreMatchPanel.challengeBtn.width,PreMatchPanel.challengeBtn.height);
			step();
			//指向挑战按钮
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  PreMatchPanel.challengeBtn;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete3);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
		}
		/**
		 *开始加载比赛资源 
		 */		
		private var panelUI :MatchPanel;//比赛框
		private function onLoadResStart2_0(e:NotifierEvent):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
			removeArrowMc();
			sceneBtn = null;
			GlobalDef.AlertContainer.addChild(bgMark);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:7}));
			panelUI = e.params as MatchPanel;
			panelUI.removeEvtListener();
		}
		/**
		 *球队介绍完毕 
		 * @param e
		 * 
		 */		
		private function onLoadResComplete3(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete3);
			TweenLite.delayedCall(10,initDialog_3);
			GlobalDef.GameContainer.addChild(bgMark);
			sceneBtn = null;
			//限制区域
			var rectPoint :Point = panelUI.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y + 80,panelUI.width,panelUI.height - 80);
			step();
		}
		/**
		 * 场景内对话框 
		 *	信息面板
			官方：比赛的当前比分和时间！
			1L：中央电视台，中央电视台，中央电视台。
			2L：电脑鸡前面的观众盆友，
			3L：您现在看到的是
		 * 
		 */		
		private function initDialog_3():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_12");
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn3_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn3_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn3_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			//第7步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:7}));
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn3_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(MainEvent.OPEN_LEAGUEMATCH_VIEW,openViewH);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete3);
			super.clear();
			panelUI = null;
			TweenLite.killTweensOf(initDialog_3);
		}
	}
}